//
//  railwaysController.h
//  ElektroM
//
//  Created by Michael on 09.10.09.
//  Copyright 2009 Artgruppe inc. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "drawingCanvas.h"
#import "dataBase.h"
#import "timeTableView.h"
#import "controllerWithTab.h"
#import "showTime.h"


#define kWhereCount 20

@class timeTableView;
@class chooseStation;
@class showInfoWindow;

@interface railwaysController : controllerWithTab 
				<UINavigationBarDelegate, UIActionSheetDelegate, UITextFieldDelegate> 
{
	NSString* databaseName;				//database-identifier, without Railways.sqlite prefix
	IBOutlet UIScrollView* scrollView;  // scroll view, 
	IBOutlet drawingCanvas* canvas;		// drawing canvas for showing info of selected stations;
	UIImageView* 		image;			// image for each railway
	// for the message about resources in use:
	bool 			_bUnneededStuffWasReleased;
	bool 			_bAllCUnneededStuffWasReleased;
		
	NSString* 		name;			//holds the name of the railway direction, i.e. Belorusskoye
	
	dataBase* 		_db;			//DB-instance
	bool			_bAreWeInScrollMode;	
		
	NSArray* 		_aiStationNames;	//Apple-names of all stations;
	NSArray*		_aiCentersX;
	NSArray*		_aiCentersY;
	NSDictionary* 		_diNodes;
	NSArray* 		_aiNext;
	// structure:
	NSMutableArray*		_aiParents;
	NSMutableArray* 	_aiWeights;

	// indexes in the centers of railways
	// centersOfRailways which shows what station was selected
	int 			_nFirstFoundStation;	
	int 			_nSecondFoundStation;
	// if we need to update our canvas...
	bool 			_bReformDrawBuffer;

	//Knots* 			_myKnots;		//converted structure of railways for Graph-class	
	
	bool 			_bLoadSubControllers;	// tabBar dancing stuff (see in realization)
	bool 			_bWasResized;		// also dancing with tabBar
	
	// testing purpose for animation:
	double 			_dyAnimation;
	CGPoint 		_ptWhereLast;
	bool 			_bNeedToCalculateGraph;
	int 			_nLastFirstStation;
	int 			_nLastSecondStation;

	timeTableView* 		timeTableController;
	
	chooseStation* 		stationSelectController;	
													
	int 			_nTextFieldStationSelection;	
	showTime* 		showTimeWindow;	
	UINavigationController* navController;

	// sightseeing:
	IBOutlet UIView* 	showSightseeings;
	// sightseeing stations' ids:
	NSArray*		_aiSStationIds;
	int 			_nAmountSightSeeingStIds;

	bool 			_bSightsWereShown;
	int  			_nLastNumber;
	bool 			_bHideInfoPanelWasForced;
	bool			_bShowQuer;
	// info window on sightseeing...
	showInfoWindow* 	infoWindow;
	
	// bottom Toolbar
	IBOutlet UIView* 	bottomToolbar;
	IBOutlet UITextField* 	btnStationStart;
	IBOutlet UITextField* 	btnStationEnd;	
	// station time labels
	IBOutlet UILabel* 	lblTimeStation1ToMoscow;
	IBOutlet UILabel* 	lblTimeStation1FromMoscow;
	IBOutlet UILabel* 	lblTimeStation2ToMoscow;
	IBOutlet UILabel* 	lblTimeStation2FromMoscow;
}
@property (nonatomic,retain) IBOutlet UINavigationController* navController;
// labels
@property (nonatomic,retain) IBOutlet UILabel* lblTimeStation1ToMoscow;
@property (nonatomic,retain) IBOutlet UILabel* lblTimeStation1FromMoscow;
@property (nonatomic,retain) IBOutlet UILabel* lblTimeStation2ToMoscow;
@property (nonatomic,retain) IBOutlet UILabel* lblTimeStation2FromMoscow;	
// labels
@property (nonatomic,retain) chooseStation* stationSelectController;
@property (nonatomic,retain) NSString* databaseName;
@property (nonatomic,retain) IBOutlet UIScrollView* scrollView;
@property (nonatomic,retain) UIImageView* image;
@property (nonatomic,retain) IBOutlet drawingCanvas* canvas;

@property (nonatomic,retain) timeTableView* timeTableController;

// toolbar:
@property (nonatomic,retain) IBOutlet UIView* bottomToolbar;
@property (nonatomic,retain) IBOutlet UITextField* btnStationStart;
@property (nonatomic,retain) IBOutlet UITextField* btnStationEnd;

// for showing the name of the railway direction
@property (nonatomic,retain) NSString* name;

-(void)findStationInPoint:(CGPoint) ptCur;
-(void) performGraphCalc;

-(void) drawSelection;
-(void) drawNodeNormalStation:(bool)bOrdinal Color:(UIColor*)color StationIndex:(int)index;

-(IBAction) showTimeTable:(id)button;
-(IBAction) resetStation:(id)button;
-(void) setSelection:(int)selected;
-(void) recalculateGraph;
-(void) updateInterface;
-(void) updateFromDBStationsInfo;
-(IBAction) showTimes;
-(IBAction) showInfoWindow;

-(void)fadeOutToolbar:(NSTimer*)theTimer;
-(void)fadeInToolbar:(NSTimer*)theTimer;
-(void) hideToolbarWithAnimationAndInfo:(int)nInfo;
-(void) showToolbarWithAnimationAndInfo:(int)nInfo;
-(void) loadAllNeededStuff;
-(void) releaseAllStuff;
-(bool) unneededStuffWasReleased;
-(void) drawLineWithColor:(UIColor*)color withPoint:(CGPoint)pt;
-(void) drawLineWithColor:(UIColor*)color StationIndex:(int)index;
-(void) applyCyclonToWholeStructure:(int)Start;
-(void) relaxNode:(int)nRelaxing withNode:(int)nFrom withWeight:(int)nWeight;
-(void) showInfoOnAnyOfStations;
-(void) showToolbarInfoWithAnimationAndInfo:(int)nInfo;
-(void) hideToolbarInfoWithAnimationAndInfo:(int)nInfo;
-(void) fadeInToolbarInfo:(NSTimer*)theTimer;
-(void) fadeOutToolbarInfo:(NSTimer*)theTimer;
-(void) enableUserInteraction;
-(void) disableUserInteraction;
-(void) acquireInfoAboutSecondStation;
-(void) acquireInfoAboutFirstStation;
-(void) setQuer:(bool) bQuer;
@end
